package com.example.jchuah.tiles;

import android.app.Activity;
import android.os.Bundle;
import android.view.DragEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.GridLayout;
import android.widget.RelativeLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.GridLayout;
import android.view.ViewGroup.LayoutParams;


public class MyActivity extends Activity implements View.OnTouchListener, View.OnDragListener {

    int numRows = 4;
    int numCols = 4;

    View[][] grid = new View[numRows][numCols];
    GridLayout gridLayout;

    public void generateGrid() {
        for (int row = 0; row < numRows; row++){
            for (int col = 0; col < numCols; col++) {
                View tile = getLayoutInflater()
                        .inflate(R.layout.tile, null);

                addTile(row, col, tile);
            }
        }
    }

    public void addTile(int row, int col, View tile) {
        GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
        layoutParams.rowSpec = GridLayout.spec(row);
        layoutParams.columnSpec = GridLayout.spec(col);
        tile.setLayoutParams(layoutParams);

        gridLayout.addView(tile);
        grid[row][col] = tile;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        gridLayout = (GridLayout)findViewById(R.id.gridView);
        generateGrid();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onDrag(View view, DragEvent dragEvent) {
        return false;
    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        return false;
    }
}
